﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Maticsoft.DAL.CarrefourCover
{
    public partial class ShortMessage
    {
        public int SetAllRead( int receiveuid )
        {
            SqlParameter[] parameters = 
            {
                new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = receiveuid;
            return DBUtility.DbHelperSQL.ExecuteSql( "UPDATE shortmessage SET ISREAD = 1 WHERE RecevieBabyId = @id", parameters );
        }

        public int getNewCount( int receiveuid )
        {
            SqlParameter[] parameters = 
            {
                new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = receiveuid;
            return Convert.ToInt32( DBUtility.DbHelperSQL.GetSingle( "SELECT COUNT(1) FROM shortmessage WHERE ISREAD = 0 AND RecevieBabyId = @id", parameters ) );
        }

        public int getTodaySendCount( int senduid )
        {
            SqlParameter[] parameters = 
            {
                new SqlParameter("@id", SqlDbType.Int,4),
                new SqlParameter("@date", SqlDbType.DateTime2 )
            };
            parameters[0].Value = senduid;
            parameters[1].Value = DateTime.Today;
            return Convert.ToInt32( DBUtility.DbHelperSQL.GetSingle( "SELECT COUNT(1) FROM shortmessage WHERE SendBabyID = @id AND MsgType=1 AND CreateTime > @date", parameters ) );
        }
    }
}
